package com.sise.netty.server端和client端通信案例.整合版本;


import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringEncoder;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;

/**
 * @author idea
 * @data 2019/1/23
 */
public class NettyClient {

    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        Bootstrap bootstrap=new Bootstrap();
        NioEventLoopGroup group=new NioEventLoopGroup();
        bootstrap.group(group)
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel channel) throws Exception {
                        channel.pipeline().addLast(new StringEncoder());
                    }
                });
        Channel channel=bootstrap.connect("localhost",8000).channel();
        while (true) {
            System.out.println("发送数据");
            channel.writeAndFlush(new Date()+":ahhahsjkdhajksdh");
            Thread.sleep(2000);
        }

    }


}


